#pragma once

#include "IXHotKeySrv.h"
#include "XBaseObjImpl.h"

typedef std::map<UINT, IXHotKeyHandler*>   HotKeyHandlerContainer;

class CXHotKeySrvImpl : public CXBaseObjImpl<IXHotKeySrv>
{
    typedef CXBaseObjImpl<IXHotKeySrv> superclass;
    DEF_SKIN_CLASS_SINGLE_INTF(CXHotKeySrvImpl,
        superclass,
        gs_strGuidXSkin,
        IXHotKeySrv,
        eIntf_Singleton);

public:
    CXHotKeySrvImpl();
    virtual ~CXHotKeySrvImpl();

public:
    // IXHotKeySrv
    virtual UINT_PTR STDMETHODCALLTYPE   AddHotKeyHandler(UINT uModifiers, UINT uVk, IXHotKeyHandler* pListener);
    virtual void     STDMETHODCALLTYPE   DelHotKeyHandler(UINT_PTR uHotKeyId);
    virtual void     STDMETHODCALLTYPE   DelHotKeyHandler(IXHotKeyHandler* pHandler);
    virtual BOOL     STDMETHODCALLTYPE   IsHotKeyValid(UINT uModifiers, UINT uVk);

public:
    // IXBaseObj
    virtual void    STDMETHODCALLTYPE   OnFinalRelease();

protected:
    static LRESULT CALLBACK HotKeyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

protected:
    HWND        GetHotKeyWnd();
    BOOL        HandleHotKeyMsg(UINT_PTR uHotKeyId);

protected:
    HotKeyHandlerContainer    m_HotKeyHandlerCont;

    HWND            m_hHotKeySrvWnd;
};

